package com.shangjinrong.controller.site;

import com.shangjinrong.domain.vo.BorrowerVO;
import com.shangjinrong.result.R;
import com.shangjinrong.service.BorrowerService;
import com.shangjinrong.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("site/borrower")
public class SiteBorrowerController {
    @Autowired
    private BorrowerService borrowerService;

    @PostMapping("save")
    public R save(@RequestBody BorrowerVO borrowerVO, HttpServletRequest request) {
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerByUserId(borrowerVO, userId);
        return R.ok().message("信息提交成功");
    }

    @GetMapping("getStatus")
    public R getStatus(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        return R.ok().data("status",borrowerService.getStatus(userId));
    }
}

